package cn.com.myspring.framework.aop.aspect;

import java.lang.reflect.Method;

import cn.com.myspring.framework.aop.intercept.MYMethodInterceptor;
import cn.com.myspring.framework.aop.intercept.MYMethodInvocation;

public class MYMethodBeforeAdviceInterceptor extends MYAbstractAspectAdvice implements MYAdvice,MYMethodInterceptor {


    private MYJoinPoint joinPoint;
    /**
     * @Description 构造前置通知
     * @param aspectMethod 切面方法
     * @param aspectTarget 切面对象
     */
    public MYMethodBeforeAdviceInterceptor(Method aspectMethod, Object aspectTarget) {
        super(aspectMethod, aspectTarget);
    }

    @Override
    public Object invoke(MYMethodInvocation mi) throws Throwable {
        //从被织入的代码中才能拿到，JoinPoint
        this.joinPoint = mi;
        // 执行前置通知
        before(mi.getMethod(), mi.getArguments(), mi.getThis());
        // 继续往下执行
        return mi.proceed();
    }
    
    /**
     * @Description 调用前置通知
     * @param method
     * @param args
     * @param target
     * @throws Throwable
     */
    private void before(Method method,Object[] args,Object target) throws Throwable{
        //传送了给织入参数
        super.invokeAdviceMethod(this.joinPoint,null,null);
    }
}
